package de.htw.praxisprojekt.actions;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import de.htw.praxisprojekt.ExportUtils;
import de.htw.praxisprojekt.LineAlgo;

public class ExportAction implements ActionListener{

	private LineAlgo lineAlgo;

	public ExportAction(LineAlgo lineAlgo){
		this.lineAlgo=lineAlgo;
	}

	public void actionPerformed(ActionEvent arg0){
		JFileChooser fileChooser=new JFileChooser(".");
		fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setFileFilter(new FileNameExtensionFilter(ExportUtils.EXT_JPG,ExportUtils.EXT_JPG));
		fileChooser.setFileFilter(new FileNameExtensionFilter(ExportUtils.EXT_PNG,ExportUtils.EXT_PNG));
		fileChooser.setFileFilter(new FileNameExtensionFilter(ExportUtils.EXT_GIF,ExportUtils.EXT_GIF));
		fileChooser.setFileFilter(new FileNameExtensionFilter(ExportUtils.EXT_EPS,ExportUtils.EXT_EPS));
		fileChooser.showSaveDialog((Component)arg0.getSource());
		String extension=fileChooser.getFileFilter().getDescription();
		File selectedFile=fileChooser.getSelectedFile();
		if(selectedFile!=null){
			ExportUtils.export(selectedFile,extension,lineAlgo);
		}
	}
}
